//
//  SAProductHomeScreeningHeaderView.m
//  yidiantong
//
//  Created by 黄志刚 on 2020/10/26.
//

#import "SAProductHomeScreeningHeaderView.h"
@interface SAProductHomeScreeningHeaderView()

@property (nonatomic,strong) UILabel *hitLabel;
@property (nonatomic,strong) UILabel *hitLabel1;
@property (nonatomic,strong) UIButton * anBtn;
@property (nonatomic ,assign) BOOL selected;
@property (nonatomic,strong) UIView *btnView;

@end

@implementation SAProductHomeScreeningHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor clearColor];
        [self creatUI];
    }
    return self;
}

-(void)creatUI
{
    self.userInteractionEnabled = YES;
    
    UILabel *hitLabel = [[UILabel alloc] init];
    hitLabel.textAlignment = NSTextAlignmentLeft;
    hitLabel.textColor = kBlackColor;
    hitLabel.font = kBFont(16);
    [self addSubview:hitLabel];
    self.hitLabel = hitLabel;
    [hitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(kScaleNum(0)));
        make.top.equalTo(@(kScaleNum(20)));
        make.width.mas_equalTo(kScaleNum(100));
        make.height.mas_equalTo(kScaleNum(32));
    }];
    
    UILabel *hitLabel1 = [[UILabel alloc] init];
    hitLabel1.textAlignment = NSTextAlignmentRight;
    hitLabel1.frame = CGRectMake(kScaleNum(85), kScaleNum(20), kScaleNum(200), kScaleNum(32));
    hitLabel1.textColor = kBlackColor;
    hitLabel1.font = kFont(14);
    [self addSubview:hitLabel1];
    self.hitLabel1= hitLabel1;
    
    UIButton * anBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    anBtn.hidden = YES;
    anBtn.frame = CGRectMake(kScaleNum(275), kScaleNum(34), kScaleNum(10), kScaleNum(5));
    if (_selected == YES) {
        [anBtn setBackgroundImage:[UIImage imageNamed:@"product_screening_header_btn_s"] forState:UIControlStateNormal];
    }else
    {
        [anBtn setBackgroundImage:[UIImage imageNamed:@"product_screening_header_btn_n"] forState:UIControlStateNormal];
    }
    
    //[anBtn addTarget:self action:@selector(anBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:anBtn];
    self.anBtn = anBtn;
    
    UIView *btnView = [[UIView alloc] initWithFrame:CGRectMake(kScaleNum(85), kScaleNum(20), kScaleNum(200), kScaleNum(32))];
    btnView.userInteractionEnabled = YES;
    btnView.backgroundColor = [UIColor clearColor];
    UITapGestureRecognizer *btnViewTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(btnViewTapEvent:)];
    [btnView addGestureRecognizer:btnViewTap];
    [self addSubview:btnView];
    self.btnView = btnView;
}

-(void)loadData:(SAProductHomeScreeningModel *)model
{
    self.hitLabel.text = model.name;
    if (model.voList.count > 6) {
        self.anBtn.hidden = NO;
        self.hitLabel1.frame = CGRectMake(kScaleNum(68), kScaleNum(20), kScaleNum(200), kScaleNum(32));
    }else
    {
        self.anBtn.hidden = YES;
        self.hitLabel1.frame = CGRectMake(kScaleNum(85), kScaleNum(20), kScaleNum(200), kScaleNum(32));
    }
    for (SAProductHomeScreeningList *list in model.voList) {
        if (list.check == YES) {
            self.hitLabel1.text = list.attrName;
        }
    }
    if (model.isOpen == YES) {
        _selected  = YES;
    }else
    {
        _selected  = NO;
    }
    
    if (_selected == YES) {
        [self.anBtn setBackgroundImage:[UIImage imageNamed:@"product_screening_header_btn_s"] forState:UIControlStateNormal];
    }else
    {
        [self.anBtn setBackgroundImage:[UIImage imageNamed:@"product_screening_header_btn_n"] forState:UIControlStateNormal];
    }
}

-(void)loadDataa:(SAProductHomeScreeningModel *)model
{
    self.hitLabel.text = model.name;
    if (model.voList.count > 6) {
        self.anBtn.hidden = NO;
        self.hitLabel1.frame = CGRectMake(kScaleNum(68), kScaleNum(20), kScaleNum(200), kScaleNum(32));
    }else
    {
        self.anBtn.hidden = YES;
        self.hitLabel1.frame = CGRectMake(kScaleNum(85), kScaleNum(20), kScaleNum(200), kScaleNum(32));
    }
    for (SAProductHomeScreeningList *list in model.voList) {
        if (list.check == YES) {
            self.hitLabel1.text = list.conditionName;
        }
    }
    if (model.isOpen == YES) {
        _selected  = YES;
    }else
    {
        _selected  = NO;
    }
    
    if (_selected == YES) {
        [self.anBtn setBackgroundImage:[UIImage imageNamed:@"product_screening_header_btn_s"] forState:UIControlStateNormal];
    }else
    {
        [self.anBtn setBackgroundImage:[UIImage imageNamed:@"product_screening_header_btn_n"] forState:UIControlStateNormal];
    }
}
-(void)loadDat:(SACurrentAccountHomeScreeningModel *)model
{
    self.hitLabel.text = model.name;
    if (model.conditionVOS.count > 6) {
        self.anBtn.hidden = NO;
        self.hitLabel1.frame = CGRectMake(kScaleNum(68), kScaleNum(20), kScaleNum(200), kScaleNum(32));
    }else
    {
        self.anBtn.hidden = YES;
        self.hitLabel1.frame = CGRectMake(kScaleNum(85), kScaleNum(20), kScaleNum(200), kScaleNum(32));
    }
    for (SACurrentAccountHomeScreeningList *list in model.conditionVOS) {
        if (list.check == YES) {
            self.hitLabel1.text = list.name;
        }
    }
    if (model.isOpen == YES) {
        _selected  = YES;
    }else
    {
        _selected  = NO;
    }
    
    if (_selected == YES) {
        [self.anBtn setBackgroundImage:[UIImage imageNamed:@"product_screening_header_btn_s"] forState:UIControlStateNormal];
    }else
    {
        [self.anBtn setBackgroundImage:[UIImage imageNamed:@"product_screening_header_btn_n"] forState:UIControlStateNormal];
    }
}

-(void)btnViewTapEvent:(UITapGestureRecognizer *)sender
{
    _selected = !_selected;
    
    if(_selected) {
        [self.anBtn setBackgroundImage:[UIImage imageNamed:@"product_screening_header_btn_s"] forState:UIControlStateNormal];
    }else {
        [self.anBtn setBackgroundImage:[UIImage imageNamed:@"product_screening_header_btn_n"] forState:UIControlStateNormal];
    }
    if (self.anScreenBlock) {
        self.anScreenBlock(_selected);
    }
}

@end
